﻿<UserControl x:Class="ConsoleHoster.View.Controls.CommandPresenter"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <ItemsControl ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>

        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Expander HorizontalAlignment="Stretch" VerticalAlignment="Top" HorizontalContentAlignment="Stretch" IsExpanded="True" Margin="0, 0, 0, 3" Padding="2, 0, 2, 3" BorderThickness="1, 0, 1, 1">
                    <Expander.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF9BB8CC" Offset="0"/>
                            <GradientStop Color="Blue" Offset="1"/>
                        </LinearGradientBrush>
                    </Expander.BorderBrush>
                    <Expander.Header>
                        <TextBlock Text="{Binding Path=Key}" FontWeight="Bold" />
                    </Expander.Header>
                    <ItemsControl ItemsSource="{Binding Value}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>

                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Button Content="{Binding UIFriendlyName}" Command="{Binding DataContext.CustomConsoleCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" CommandParameter="{Binding}" Cursor="Hand" HorizontalAlignment="Stretch" Margin="0, 0, 0, 1" Background="{Binding Path=ColorBrush}" ToolTip="Ctrl+Click for command text" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Expander>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</UserControl>
